home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.786 < prev    next >
Text File  |  1992-02-06  |  2KB  |  47 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Ohlfs;\f1\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\b0\i0\ul0\fs28\fc0 NXImage NXImageRep writeTIFF:
  8. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 \
  9. \
  10. Q:  My application is a simple paint program.  The user opens a TIFF image, then scribbles into it, and finally saves the new image as a TIFF file.  However, the changes made by the user aren't saved into the TIFF file—it contains the original image.  Why?\
  11. \
  12. A:  This will occur if you open the TIFF file like this:\
  13. \
  14.  
  15. \f3\fs22     image = [[NXImage alloc] initFromFile:fileName];\
  16.  
  17. \f0\fs28 \
  18. NXImage will have two representations—the file, and the cache.  NXImage will treat the cache as a transitory image, and the file as its "best representation."  The cache is the off-screen window to which the user's scribbles are drawn.  When asked to write out the image, NXImage writes out its best representation of the image—which is the actual TIFF file residing on disk—thus ignoring completely the changes made to the image.  To get around this you must fake out NXImage by forcing the cache to be the best representation of the image.\
  19. \
  20. The following code snippet illustrates what you must do:\
  21. \
  22.  
  23. \f3\fs22     /*  When the user opens the image */\
  24.     rep = [[NXBitmapImageRep alloc] initFromFile:fileName];\
  25.     [rep getSize:&imageSize];\
  26. \
  27.     image = [[NXImage alloc]  initSize:&imageSize];\
  28. \
  29.     if ([image useCacheWithDepth:d] && [image lockFocus]) \{\
  30.         [rep draw];\
  31.         [image unlockFocus];\
  32.     \}\
  33.     [rep free];\
  34.  
  35. \f0\fs28 \
  36.  
  37. \fc0 This code sample initialized an NXBitmapImageRep from the file containing the opened image.  The NXImage is initialized from this representation.  Now the NXImage does not have a file which can serve as its best representation—it only has the cache.  Thus when you tell NXImage to 
  38. \b writeTIFF:
  39. \b0  the cache with all of the user's scribbles will be written out properly.\
  40. \
  41. QA786\
  42. \
  43. Valid for 1.0\
  44. Valid for 2.0\
  45. \
  46.  
  47.